package com.zd.commodity.productMng.dao.impl;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.zd.commodity.dao.impl.BaseDao;
import com.zd.commodity.productMng.dao.INameProductRuleDao;
import com.zd.commodity.productMng.entity.NameProductRule;

@Repository("nameProductRuleDao")
public class NameProductRuleDaoImpl extends BaseDao<NameProductRule> implements
		INameProductRuleDao {

	@Resource(name = "sessionFactory")
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	@Override
	public DetachedCriteria getDetachedCriteria(NameProductRule t1,NameProductRule t2,Object params){
		DetachedCriteria dc=DetachedCriteria.forClass(NameProductRule.class);
		if(t1!=null){
			if(t1.getCategory()!=null&&t1.getCategory().getId()!=null){
				dc.add(Restrictions.eq("category.id", t1.getCategory().getId()));
			}
			if(t1.getBrandShow()!=null&&t1.getBrandShow().getId()!=null){
				dc.add(Restrictions.eq("brandShow.id", t1.getBrandShow().getId()));
			}
		}
		return dc;
	}
}
